package com.codeest.geeknews.widget;

import android.content.Context;
import android.graphics.drawable.Animatable;
import android.os.Build;
import android.support.v7.widget.AppCompatImageView;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by codeest on 16/9/27.
 */

public class ProgressImageView extends AppCompatImageView {


    public ProgressImageView(Context context) {
        super(context);
    }

    public ProgressImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ProgressImageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void start() {
        setVisibility(View.VISIBLE);
        if (Build.VERSION.SDK_INT >= 21) {
            Animatable animatable = (Animatable) getDrawable();
            if (!animatable.isRunning()) {
                animatable.start();
            }
        }
    }

    public void stop() {
        if (Build.VERSION.SDK_INT >= 21) {
            Animatable animatable = (Animatable) getDrawable();
            if (animatable.isRunning()) {
                animatable.stop();
            }
        }
        setVisibility(View.GONE);
    }
}
